/**
 * WatermelonJS,西瓜JS框架。
 * 这是一个基于JQuery的JavaScript框架。
 * http://code.google.com/p/watermelon-js/
 * 论坛：http://watermelonjs.5d6d.com
 * email: psh24053@yahoo.cn
 */

/**
 * Watermelon基础类，构造一个Html窗口。
 * @param body Object body元素的对象，可以是JQuery对象也可以是Dom对象;
 * 
 * 
 */
function Watermelon(body){

	this.body = body;
	var p_this = this;
	
	/**
	 * add方法，向窗口中增加元素
	 * 
	 */
	this.add = function(){
		
	};
	
	/**
	 * alert方法，创建一个对话框
	 */
	this.alert = function(object){
		var div = $("<div></div>").css("width",350).css("height",135).css("position","absolute").css("top","50%").css("left","50%").css("border","solid 1px red").css("margin-top",-98).css("margin-left",-175).text(object);
		$(this.body).append(div);
	};
	/**
	 * getPanel方法，构造一个面板，并返回本身
	 * @param PanelSettings JsonObject
	 * @returns Watermelon_Panel Object
	 */
	this.getPanel = function(PanelSettings){
		return new Watermelon_Panel(PanelSettings);
	};
	/**
	 * Watermelon_Panel类
	 * @param PanelSettings JsonObject
	 */
	function Watermelon_Panel(PanelSettings){
		
	}
	
	/**
	 * getDialog方法，构造一个Dialog类，并返回本身
	 * @param DialogSettings JsonObject
	 * @returns Watermelon_Dialog Object
	 */
	this.getDialog = function(DialogSettings){
		return new Watermelon_Dialog(DialogSettings);
	};
	/**
	 * Watermelon_Dialog类
	 * @param DialogSettings JsonObject
	 */
	function Watermelon_Dialog(DialogSettings){

		var width = DialogSettings.width;
		var height = DialogSettings.height;
		var content = DialogSettings.content;
		var onOpen = DialogSettings.onOpen;
		var onClose = DialogSettings.onClose;
		var w_dialog_localtion = null;
		var w_dialog = null;
		this.open = function (){
			if(onOpen != undefined){
				onOpen();
			}
			if(typeof(content) == "string"){
				w_dialog_localtion = $("<div></div>").css("height",height).css("width",width).css("left","50%").css("top","50%").css("position","absolute");
				w_dialog = $("<div></div>").css("color","#ffffff").css("height",height).css("width",width).css("left","-50%").css("top","-50%").css("position","relative").css("border","solid 1px red").css("background-color","#000000").text(content);
				$(w_dialog_localtion).html(w_dialog);
				$(p_this.body).append(w_dialog_localtion);
			}
			
			

		};
		this.close = function(){
			if(onClose != undefined){
				onClose();
			}
			$(w_dialog).remove();
			$(w_dialog_localtion).remove();
			
		};
		
	}
}
